package edu.guigu.appquickstart.datastore.bean;

import android.icu.text.Collator;

import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Locale;

/**
 * @author yuanc
 * @Description: (用一句话描述)
 * @date 2025/8/12 20:19
 */
public class UserBean {
    private int id;
    private String name;
    private String email;
    private int age;
    private String registerTime;

    // 构造方法
    public UserBean() {
    }

    public UserBean(String name, String email, int age) {
        this.name = name;
        this.email = email;
        this.age = age;
    }

    // Getter和Setter方法
    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getEmail() {
        return email;
    }

    public String getRegisterTime() {
        return registerTime;
    }

    public void setRegisterTime(String registerTime) {
        this.registerTime = registerTime;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "UserBean{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", email='" + email + '\'' +
                ", age=" + age +
                ", registerTime=" + registerTime +
                '}';
    }


    public static void userSort(List<UserBean> dataList, String sortField, boolean isAsc) {
        // 中文排序规则(按拼音排序)
        Collator collator = Collator.getInstance(Locale.CHINA);
        collator.setStrength(Collator.PRIMARY); // 设置比较强度
        // 排序（使用比较器）
        Collections.sort(dataList, new Comparator<UserBean>() {
            int result = 0;

            @Override
            public int compare(UserBean o1, UserBean o2) {
                switch (sortField) {
                    case "name":
                        result = collator.compare(o1.getName(), o2.getName());
                        break;
                    case "age":
                        result = Integer.compare(o1.getAge(), o2.getAge());
                        break;
                    default:
                        result = Integer.compare(o1.getId(), o2.getId());
                        break;
                }
                return isAsc ? result : -result;
            }
        });
    }
}
